package com.elong.spring.lifecycle;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class CarLifeCycle implements BeanFactoryAware, BeanNameAware,
	InitializingBean, DisposableBean {

    private String brand;
    
    private String color;
    
    private int maxSpeed;
    
    private BeanFactory beanFactory;
    
    private String beanName;
    
    public CarLifeCycle(){
	System.out.println("调用carLifeCycle()构造函数");
    }
    
    public void setBrand(String brand){
	System.out.println("调用setBrand()设置属性");
	this.brand = brand;
    }
    
    public void introduce(){
	System.out.println("brand:" + brand + ";color:" + color + ";maxSpeed:" + maxSpeed);
    }
    
    public void setBeanFactory(BeanFactory beanFactory){
	System.out.println("调用BeanFactoryAware.setBeanFactory");
	this.beanFactory = beanFactory;
    }
    
    public void setBeanName(String beanName){
	System.out.println("调用BeanNameAware.setBeanName()");
	this.beanName = beanName;
    }
    
    public void afterPropertiesSet() throws Exception {
	System.out.println("调用InitializingBean.afterPropertiesSet()");
    }
    
    public void destroy(){
	System.out.println("调用DisposableBean.destroy()");
    }
    
    public void myInit(){
	System.out.println("调用init-method说指定的myInit(),将maxSpeed设置为240");
	this.maxSpeed = 240;
    }
    
    public void myDestroy(){
	System.out.println("调用destroy-method所指定的myDestroy()方法");
    }

    /**
     * getter method for color
     * @return the color
     */
    public String getColor() {
        return color;
    }

    /**
     * setter method for color
     * @Description the color to set
     * @param color 
     */
    public void setColor(String color) {
        this.color = color;
    }

    /**
     * getter method for maxSpeed
     * @return the maxSpeed
     */
    public int getMaxSpeed() {
        return maxSpeed;
    }

    /**
     * setter method for maxSpeed
     * @Description the maxSpeed to set
     * @param maxSpeed 
     */
    public void setMaxSpeed(int maxSpeed) {
        this.maxSpeed = maxSpeed;
    }

    /**
     * getter method for brand
     * @return the brand
     */
    public String getBrand() {
        return brand;
    }
    
    
}
